package com.dao;

import java.util.List;

import com.model.Orderitem;
import com.model.Orders;
import com.util.JdbcUtil;

public class OrderItemDao {
	JdbcUtil jdbc=new JdbcUtil();
	//添加一条订单页信息
	public void add(Orderitem item) throws Exception{
		String sql ="insert into orderitem values(?,?,?,?,?,?,?,?,?,?)";
		jdbc.updatePreparedStatement(sql,item.getOiid(),item.getOid(),item.getUid(),
				item.getPid(),item.getEid(),item.getPname(),item.getPimage(),
				item.getPprice(),item.getWeight(),item.getTprice());
		jdbc.close();
	}
	
	//订单详情页进行分页展示
	public List<Orderitem> queryItem_show(Orderitem item,int cp,int pagesize){
		List<Orderitem> orderitems = null;
		StringBuffer sql = new StringBuffer("select * from orderitem where 1=1");
		if(item.getOid()!=null && !item.getOid().equals("")){
			sql.append(" and oid = '"+item.getOid()+" ' ");
		}
		sql.append(" order by oid ");
		//外层分页语句
		StringBuffer sb = new StringBuffer();
		sb.append(sql);
		sb.append(" limit "+(cp-1)*pagesize+","+(cp)*pagesize);
		
		System.out.println(sb.toString());
		orderitems  = jdbc.queryPreparedStatement(sb.toString(), Orderitem.class);
		jdbc.close();
		return orderitems ;
	}
	//查询总条数 根据需求变化,与queryItem_show搭配使用
	public int count_user(Orderitem item){
		StringBuffer sql = new StringBuffer("select * from orderitem where 1=1");
		if(item.getOid()!=null && !item.getOid().equals("")){
			sql.append(" and oid = '"+item.getOid()+"'");
		}
		List<Orderitem> temp=jdbc.queryPreparedStatement(sql.toString(), Orderitem.class);
		jdbc.close();
		return temp.size();
	}
}
